<template>
  <div class="myview">
    <van-nav-bar
      title="个人中心"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />

    <div class="one-o">
      <div class="left">
        <img src="../assets/wechat.png" alt="" />
      </div>
      <div class="p-login" @click="gologin()" v-if="showname" style="color:#000">{{ '欢迎您'+tel }}</div>
      <div class="p-login" @click="gologin()" v-if="checklogin">请您先登录</div>
    </div>

    <div class="two-o">
      <div class="btn">
        <div><van-icon class="icons" name="gold-coin-o" /></div>
        <div>待付款</div>
      </div>
      <div class="btn">
        <div><van-icon class="icons" name="shop-o" /></div>
        <div>待收货</div>
      </div>
      <div class="btn">
        <div><van-icon class="icons" name="good-job-o" /></div>
        <div>待评价</div>
      </div>
      <div class="btn">
        <div><van-icon class="icons" name="orders-o" /></div>
        <div>全部订单</div>
      </div>
    </div>

    <div class="three-o" v-for="(item, index) in btns" :key="index">
      <div>{{ item }}</div>
      <div><van-icon name="arrow" /></div>
    </div>

    <BottombarCom />
  </div>
</template>

<script>
import { fun_userinfo } from "../api/index.js";
import { Toast } from "vant";
export default {
  data() {
    return {
      btns: ["地址管理", "我的收藏夹", "关于我们"],
      token: "",
      showname: false,
      userid: "",
      msg: {},
      key: "",
      tel:'',
      checklogin:true
    };
  },
  methods: {
    onClickLeft() {
      Toast("返回");
      this.$router.go(-1);
    },
    gologin() {
      if (localStorage.getItem("token")) {
        
        this.$router.push("homepage");
      } else {
        this.$router.push("login");
      }
    },
  },
  created() {
    this.userid = localStorage.getItem("userid");
    // console.log(this.userid);

    if(localStorage.getItem("token")){
      this.showname=true
      this.checklogin=false
    }else{
      this.showname=false
      this.checklogin=true
    }
    fun_userinfo(this.userid).then((res) => {
      // console.log(...res.data.data);
      this.msg = res.data.data;
      const obj = { ...this.msg };
      for (this.key in obj) {
        this.tel=obj[this.key].tel
      }
    });
  },
 
};
</script>

<style lang="scss" scoped>
.one-o {
  // background-color: pink;
  width: 100%;
  display: flex;
  padding: 0.4444rem 0.5556rem;
  background-color: #fff;
  box-sizing: border-box;
}
.one-o .left {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  border: 1px solid rgb(230, 230, 230);
  background-color: #fff;
  margin-top: 0.8333rem;

  img {
    width: 100%;
    border-radius: 50%;
  }
}
.p-login {
  margin-left: 0.5556rem;
  line-height: 6.1111rem;
  color: #ccc;
}
.two-o {
  background-color: #fff;
  margin-top: 0.4444rem;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4444rem 0.5556rem;
  box-sizing: border-box;
  border-bottom: 1px solid rgb(239, 239, 239);
}
.two-o .btn {
  text-align: center;
}
.icons {
  font-size: 1.6667rem;
  margin-bottom: 0.5556rem;
}
.btn div:nth-child(2) {
  font-size: 0.7222rem;
  color: rgb(70, 70, 70);
}
.three-o {
  padding: 0.8333rem.5556rem;
  font-size: 0.7222rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
}
</style>